<!DOCTYPE HTML>
<html class="x-admin-sm">
<head>
    <th:block th:insert="head/head :: common_head"></th:block>
</head>
<body onload="init('old_pwd')">
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card" style="margin: 10px;">
                    <div class="layui-tab layui-tab-brief">
                        <div class="layui-tab-content" >
                            <div class="layui-tab-item layui-show">
                                <form class="layui-form layui-form-pane" autocomplete="off" name="myForm" id="myForm">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">
                                            <span class='x-red'>*</span>原密码：
                                        </label>
                                        <div class="layui-input-block">
                                            <input type="password" class="layui-input" id="old_pwd" name="old_pwd" placeholder="请输入原密码" onkeydown="on_key_tab('new_pwd',event);">
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">
                                            <span class='x-red'>*</span>新密码：
                                        </label>
                                        <div class="layui-input-block">
                                            <input type="password" class="layui-input" id="new_pwd" name="new_pwd" placeholder="请输入新密码" onkeydown="on_key_tab('new_pwd1',event);">
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">
                                            <span class='x-red'>*</span>新密码确认：
                                        </label>
                                        <div class="layui-input-block">
                                            <input type="password" class="layui-input" id="new_pwd1" name="new_pwd1" placeholder="请再一次输入新密码" onkeydown="on_key_button('bc',event)">
                                        </div>
                                    </div>
                                </form>
                                <button class="layui-btn" lay-submit="" lay-filter="*" id="bc">
                                    提交修改
                                </button>
                                <div style="height:100px;"></div>
                            </div>

                        </div>
                    </div>
                </div>
        </div>
    </div>
</div>
</div>
<th:block th:insert="head/head :: common_jsfiles"></th:block>
<script>
    var url = "[[${serverUrl}]]/";
    var id = "[[${id}]]";
    var sfqh="[[${sfqh}]]";
    $(document).ready(function() {
    });
    function on_result(result)
    {
        $('#bc').removeClass("layui-btn-disabled").attr("disabled",false);
        if (result.code!=500)
        {
            if (result.code==0){
                if (sfqh=="1"){
                    //新增成功
                    layer.msg("修改成功！，准备重新登录...", { time: 1000 }, function() {
                        window.parent.location.href="login";
                    });//失败时只提示信息，不关闭弹出层且不刷新父页
                }else{
                    //新增成功
                    layer.msg("修改成功！，准备重新登录...", { time: 1000 }, function() {
                        window.location.href="login";
                    });//失败时只提示信息，不关闭弹出层且不刷新父页
                }
            } else{
                layer.msg(result.msg);
            }
        }
        else
        {
            layer.msg(result.msg);
        }
    }
    //表单相关
    layui.use(['form'], function(){
        var form = layui.form;

        //监听提交
        form.on('submit(*)', function(data){

            if ($("#old_pwd").val()==""){
                layer.msg("请输入原密码！",{icon:2,anim:6});
                init('old_pwd');
                return false;
            }
            if ($("#new_pwd").val()==""){
                layer.msg("请输入新密码！",{icon:2,anim:6});
                init('new_pwd');
                return false;
            }
            if ($("#new_pwd1").val()==""){
                layer.msg("请再一次输入新密码！",{icon:2,anim:6});
                init('new_pwd1');
                return false;
            }
            if ($("#new_pwd").val()!=$("#new_pwd1").val()){
                layer.msg("两次新密码输入不一致！",{icon:2,anim:6});
                init('new_pwd');
                return false;
            }
            if (!confirm("是否确定修改密码？")) return false;
            $('#bc').addClass("layui-btn-disabled").attr("disabled",true);
            var jsonData = {
                id: id,
                old_pwd: $("#old_pwd").val(),
                new_pwd1: $("#new_pwd1").val(),
                new_pwd: $("#new_pwd").val(),
                timestamp:new Date().getTime()
            };
            var sendStr = {
                data:encrypt_str(JSON.stringify(jsonData),"NLfZ3aIOg77E2rT8","0102030405060708")
            };
            post_json_token(url+"xgmm",JSON.stringify(sendStr),"数据提交中...");
            return false;
        });
    });

</script>
</body>
</html>